package com.yunji.framework_template.books.web.controller;
import com.yunji.framework_template.books.orm.persistence.model.BooksType;
import com.yunji.framework_template.books.biz.service.BooksTypeService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;
import com.yunji.framework_template.common.web.Result;
import com.yunji.framework_template.common.web.Page;

import java.util.List;

import org.apache.ibatis.annotations.Param;

/**
 *
 * Created by fenglibin on 2019/01/24.
 */
@Controller
@RequestMapping("/booksType/")
public class BooksTypeController {

    @Autowired
    BooksTypeService booksTypeService;

    @RequestMapping("selectAll")
    @ResponseBody
    public Result<List<BooksType>> selectAll(){
        return Result.success(booksTypeService.selectAll());
    }

    @RequestMapping("select")
    @ResponseBody
    public Result<BooksType> selectByPrimaryKey(Integer id){
        return Result.success(booksTypeService.selectByPrimaryKey(id));
    }

    @RequestMapping("selectByCondition")
    @ResponseBody
    public Result<List<BooksType>> selectByCondition(BooksType record){
        return Result.success(booksTypeService.selectByCondition(record));
    }

    @RequestMapping("count")
    @ResponseBody
    public Result<Integer> count(BooksType record){
        return Result.success(booksTypeService.count(record));
    }

    @RequestMapping("insert")
    @ResponseBody
    public Result<Integer> insertSelective(BooksType record){
        return Result.success(booksTypeService.insertSelective(record));
    }

    @RequestMapping("update")
    @ResponseBody
    public Result<Integer> updateByPrimaryKeySelective(BooksType record){
        return Result.success(booksTypeService.updateByPrimaryKeySelective(record));
    }

    @RequestMapping("selectByPage")
    @ResponseBody
    public Result<Page<List<BooksType>>> selectByPage(Page<BooksType> page){
        List<BooksType> list = null;
        page = page.sequentialDisplayCalculate(booksTypeService.count(page.getObj()));
        if (page.getTotalCount() > 0) {
            list = booksTypeService.selectByPage(page);
        }
        Page<List<BooksType>> result = new Page<List<BooksType>>(page, list);
        return Result.success(result);
    }

    @RequestMapping("deleteByCondition")
    @ResponseBody
    public Result<Integer> deleteByCondition(BooksType record){
        return Result.success(booksTypeService.deleteByCondition(record));
    }

    @RequestMapping("delete")
    @ResponseBody
    public Result<Integer> deleteByPrimaryKey(Integer id){
        return Result.success(booksTypeService.deleteByPrimaryKey(id));
    }

}
